package org.oy.sealogger.app;


import org.oy.sealogger.common.Config;
import org.oy.sealogger.ds.DataSource;
import org.oy.sealogger.ds.DataSourceFactory;
import org.oy.sealogger.ds.FilteringDataSource;
import org.oy.sealogger.ds.nmea.NMEA0183DataSource;
import org.oy.sealogger.parser.CurrentState;
import org.oy.sealogger.ui.LoggerGraphics;
import org.oy.sealogger.logger.XMLLogReader;
import org.oy.sealogger.logger.XMLLogger;

import fileReader.demo.reader.Simulator;


public class SeaLogger {

	public static void main(String[] args) {
		
		Config.init(args);

		Simulator s = new Simulator();
		DataSource gps = null;
		Thread dsthread = null;
		LoggerGraphics lgraphics = new LoggerGraphics();

		CurrentState state = CurrentState.getInstance();
		XMLLogger xmllogger = new XMLLogger(state);
		state.addObserver(xmllogger);
		lgraphics.setXMLLogger(xmllogger);
		
		lgraphics.setGlassPane(s);
		lgraphics.setFrame(s);
		
		lgraphics.startObserving(state);
		
		gps = DataSourceFactory.createGPSDataSource(NMEA0183DataSource.class, false);
		
		if (gps != null) {
			gps.addObserver(state);
			((FilteringDataSource)gps).addFilter("$GPRMC");
			dsthread = new Thread(gps);
			dsthread.start();
		}

		s.setVisible(true);
		//xmllogger.stopLogging();
	}
}
